package demo1;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Semaphore;

/**
 * Created with Intellij IDEA.
 * Description:
 * User: 33013
 * Date: 2023-08-01
 * Time: 9:10
 */

class MyThread extends Thread{
    @Override
    public void run() {
        System.out.println("继承Thread");
    }
}

class MyRunnable implements Runnable{
    @Override
    public void run() {
        System.out.println("实现接口");
    }
}

public class Test {
    public static void main(String[] args) throws InterruptedException {
        MyThread thread1 = new MyThread();
        MyRunnable myRunnable = new MyRunnable();
        Thread thread2 = new Thread(){
            @Override
            public void run() {
                System.out.println("继承Thread(匿名)");
            }
        };

        Thread thread3 = new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println("实现接口(匿名)");
            }
        });

        Thread thread4 = new Thread(() -> {
            System.out.println("拉姆达表达式");
        });

        Thread thread5 = new Thread(myRunnable);
        thread1.start();
        thread2.start();
        thread3.start();
        thread4.start();
        thread5.start();
        Semaphore semaphore = new Semaphore(4);
        semaphore.acquire();
        semaphore.release();
        CountDownLatch countDownLatch = new CountDownLatch(10);
        countDownLatch.countDown();
        countDownLatch.await();
    }
}
